<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/_css.jsp"%>

<body class="gray-bg" oncontextmenu="self.event.returnValue=false">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                        <div class="jqGrid_wrapper">
                        
                            <button type="button" class="btn btn-success" >新增</button>
                            <button type="button" class="btn btn-primary" >更新</button>
                            <button type="button" class="btn btn-warning" >删除</button>
                            <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal5">高级搜索</button>
                        
                            <table id="table_list_2"></table>
                            <div id="pager_list_2"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal fade" id="addModal" tabindex="2" role="dialog"  aria-hidden="false" data-backdrop="false">
        <div class="modal-dialog modal-lg" >
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <small class="font-bold">${tableInfo.tableRemark}</small>
                </div>
                <div class="modal-body col-sm-12" id="addContent">

                          <form class="form-horizontal m-t" id="addForm" novalidate="novalidate" action="${r'${ctx}'}/${tableInfo.objectBeanName}/saveModel" method="post" > 
                            <div class="col-sm-6">
                                <div class="form-group ">
                                    <label class="col-sm-3 control-label">名称：</label>
                                    <div class="col-sm-8">
                                        <input  id="name" name="name" class="form-control" type="text" data-rule="*" data-nullmsg="名称不能为空" >
                                        <input  name="id" class="form-control" type="hidden" >
                                        <input  id="action" name="action" class="form-control" type="hidden" >
                                    </div>
                                </div>
                                
                            </div>

                            <div class="col-sm-6">

                                <div class="form-group ">
                                    <label class="col-sm-3 control-label">状态：</label>
                                    <div class="col-sm-8">
                                        <select class="form-control m-b" name="status" id="status">
                                            <option value="1">正常</option>
                                            <option value="-1">作废</option>
                                        </select>
                                    </div>
                                </div>

                            </div>
                        </form>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-info save">保存</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal fade" id="searchModel" tabindex="2" role="dialog"  aria-hidden="false" data-backdrop="false">
        <div class="modal-dialog modal-lg" >
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <button type="button" class="btn btn-info search">点击搜索</button>
                </div>
                <div class="modal-body col-sm-12" >
                    <form class="form-horizontal m-t" id="searchForm" novalidate="novalidate"  >
                        <input type="hidden" name="_search" value="false">
                        <input type="hidden" name="rows" value="10">
                        <input type="hidden" name="page" value="1">
                        <input type="hidden" name="nd" value="">

                        <div class="col-sm-6">
                            <div class="form-group ">
                                <label class="col-sm-3 control-label">名称：</label>
                                <div class="col-sm-8">
                                    <input  name="name" class="form-control" type="text" >
                                </div>
                            </div>

                            
                        </div>

                        <div class="col-sm-6">

                            <div class="form-group ">
                                <label class="col-sm-3 control-label">状态：</label>
                                <div class="col-sm-8">
                                    <select class="form-control m-b" name="status" >
                                        <option value="1">正常</option>
                                        <option value="-1">作废</option>
                                    </select>
                                </div>
                            </div>

                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    
    <%@ include file="../common/_js.jsp"%>
    <script>
        $(document).ready(function () {
            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_list_2").jqGrid({
                url:Utils.basePath  +'${tableInfo.objectBeanName}/pagelist', // java端分页的action
                datatype: "json",
                height: 380,
                autowidth: true,
                shrinkToFit: true,
                rowNum: 10,
                rowList: [10, 20, 40],
                colNames: [
                <#list tableInfo.tableColumns as columnInfo>
				   '${columnInfo.remark}'<#if columnInfo_has_next>,</#if>
				</#list>
                ],
                colModel: [
                <#list tableInfo.tableColumns as columnInfo>
				    {
                    <#if columnInfo.javaName == "status">
                    	name: '${columnInfo.javaName}',
                        index: '${columnInfo.javaName}',
                        formatter:sexFmatter
                        <#else>
                        name: '${columnInfo.javaName}',
                        index: '${columnInfo.javaName}'
                    </#if>
                    }<#if columnInfo_has_next>,</#if>
				</#list>
                    
                ],
                pager: "#pager_list_2",
                viewrecords: true,
                caption: "${tableInfo.tableRemark}列表",
                multiselect : true
            });
            $("#table_list_2").setSelection(4, true);
            $("#table_list_2").jqGrid('navGrid', '#pager_list_2', {
                edit: false,
                add: false,
                del: false,
                search: false
            });
            

            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_list_2').setGridWidth(width);
            });

            //点击添加按钮
            $(".btn-success").click(function(){
                $("#action").val("add");
                $("#addForm")[0].reset();
                <#--$("#loginName").attr("disabled",false);-->
                $('#addModal').modal('show');
            });

            //编辑
            $(".btn-primary").click(function(){
                var ids = $("#table_list_2").jqGrid('getGridParam','selarrrow');
                if(ids == null || ids.length == 0){
                    layer.alert("请选择一条数据进行操作!");
                }else if(ids != null && ids.length > 1){
                    layer.alert("您选择了多条数据,请选择一条数据进行操作!");
                }else{
                    var rowData = $("#table_list_2").jqGrid("getRowData",ids);//根据上面的id获得本行的所有数据
                    var post_data = {
                        id:rowData.id
                    };

                    $.ajax({
                        type:"post",
                        url : Utils.basePath +'${tableInfo.objectBeanName}/editJump',
                        data:post_data,
                        datatype:"json",
                        success:function(data){
                            Utils.setForm($("#addForm"), data);
                            $('#addModal').modal('show');
                            $("#action").val("update");
                            <#--$("#loginPwd").val("");
                            $("#loginPwd").attr("placeholder","填写则重置密码");
                            $("#loginPwd").removeAttr("data-rule");
                            $("#loginName").attr("disabled",true);-->
                        },
                        error:function(err){
                            layer.alert("系统异常！请联系技术支持~")
                        }
                    });

                }


            });

            //删除
            $(".btn-warning").click(function(){
            	var ids = $("#table_list_2").jqGrid('getGridParam','selarrrow');
            	
            	if(ids == null || ids.length == 0){
                    layer.alert("请选择一条数据进行操作!");
                }else{
                	 layer.confirm('您确定要删除吗？', {
                         btn: ['确定','取消'] 
                     }, function(){
                         var id="";
                         for(var i = 0;i < ids.length ;i ++) {
                             id+=ids[i]+",";
                         }
                         $.ajax({
                             url : Utils.basePath +'${tableInfo.objectBeanName}/delete',
                             data : {ids:id.substring(0,id.length-1)},
                             success  : function(data) {
                                 if(data.result){
                                     layer.alert("删除成功");
                                     setTimeout(
                                             location.href=Utils.basePath +"${tableInfo.objectBeanName}/list",300
                                     );
                                 }else{
                                     layer.alert("删除失败");
                                 }
                             }
                         });
                     }, function(){
                         layer.msg('已经取消', {shift: 6});
                     });
                	 
                }
             
            });

            //搜索
            $(".btn-danger").click(function(){
                $("#searchModel").modal("show");
                $("#searchForm")[0].reset();
            });

            //搜索
            $(".search").click(function(){
                $("#searchModel").modal("hide");
                $("#table_list_2").jqGrid('clearGridData');
                $("#table_list_2").jqGrid('setGridParam',{postData: $("#searchForm").serialize()}).trigger("reloadGrid"); 
            });



            //表单提交
            ac.form({
                area: "#addForm",   
                btn: ".save", 
                singleError: function (e, msg) {
                    layer.alert(msg);
                },
                endSuccess: function (data) {
                    <#--if("add" == $("#action").val()){
                        $.ajax({
                            url : Utils.basePath +'${tableInfo.objectBeanName}/exits',
                            data : {loginName:$("#loginName").val()},
                            success  : function(data) {
                                if(!data.result){
                                    layer.alert("该用户名已经存在!");
                                }else {
                                    $("#addForm").submit();
                                }
                            }
                          });
                    }else {
                        $("#addForm").submit();
                    }
                    -->
                    
                    $("#addForm").submit();

                }
            });

        });
      
    </script>

</body>

</html>